package deibay.client.gui;

import java.awt.event.ActionListener;

import org.jdesktop.swingx.JXFrame;

import deibay.client.core.views.IViewLogin;


import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;

import java.awt.BorderLayout;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JButton;

public class LoginView extends JXFrame implements IViewLogin{	

	private JPanel pane = null;
	private JLabel userLabel = null;
	private JLabel passLabel = null;
	private JTextField userField = null;
	private JTextField passField = null;
	private JButton loginButton = null;
	public LoginView()
	{
		super();
		initialize();
	}
	private void initialize() {
		setTitle("Login");		
		this.setContentPane(getPane());
		setSize(250,200);
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		setVisible(true);
	}
	
	/**
	 * This method initializes pane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getPane() {
		if (pane == null) {
			passLabel = new JLabel();
			passLabel.setBounds(new Rectangle(12, 50, 70, 20));
			passLabel.setText("Password ");
			userLabel = new JLabel();
			userLabel.setBounds(new Rectangle(12, 20, 40, 20));
			userLabel.setText("User ");
			pane = new JPanel();
			pane.setLayout(null);
			pane.add(userLabel, null);
			pane.add(passLabel, null);
			pane.add(getUserField(), null);
			pane.add(getPassField(), null);
			pane.add(getLoginButton(), null);
		}
		return pane;
	}
	/**
	 * This method initializes userField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getUserField() {
		if (userField == null) {
			userField = new JTextField();
			userField.setBounds(new Rectangle(85, 20, 150, 20));
		}
		return userField;
	}
	/**
	 * This method initializes passField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getPassField() {
		if (passField == null) {
			passField = new JTextField();
			passField.setBounds(new Rectangle(85, 50, 150, 20));
		}
		return passField;
	}
	/**
	 * This method initializes loginButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getLoginButton() {
		if (loginButton == null) {
			loginButton = new JButton();
			loginButton.setText("Login");
			loginButton.setBounds(new Rectangle(165, 120, 70, 25));
		}
		return loginButton;
	}
	
	public String getPassword() {
		return passField.getText();
	}

	public String getUsername() {
		return userField.getText();
	}

	public void setLoginButtonAction(ActionListener listener) {		
		loginButton.addActionListener(listener);
	}
	
	public void close() {		
		setVisible(false);
	}
	
}
